<template>
	<view class="contain">
		<view class="title">
			<div>选课结果</div>
		</view>
		<scroll-view class="list" scroll-y="true">
			<view class="items" v-show="item.isShow" v-for="(item,index) in res">
				<u-swipe-action-item :options="options" @click="dele(index)">
					<view class="info">
						<view class="coursename">
							{{item.select.course.name}}
						</view>

						<view class="teachername">
							{{item.select.teacher}}
						</view>

					</view>
					<view class="info2">
						<view class="category">
							{{item.select.course.category}}

						</view>
						<view class="credit">
							学分：{{item.select.course.credit}}
						</view>
						<view class="hour">
							总学时：{{item.select.course.total_hours}}
						</view>
					</view>
				</u-swipe-action-item>
				</u-swipe-action>
			</view>

		</scroll-view>
	</view>
</template>

<script>
	import api from '@/api/index.js'; // 引入api

	export default {
		data() {
			return {
				res: {

				},
				options: [{
					text: '退选',
					style: {
						backgroundColor: '#f56c6c'
					}
				}]
			}
		},
		onShow() {
			let token = uni.getStorageSync("token")
			api.getClass(token).then((res) => {
				if (res.code === 1) {
					this.res = res.data
					console.log(this.res)
					for (let i = 0; i < this.res.length; i++) {
						this.$set(this.res[i], "isShow", true)
					}
				} else {
					uni.showModal({
						content: res.errors
					})
				}
			}).catch((err) => {

			})
		},
		methods: {
			dele(index) {
				let token = uni.getStorageSync("token")
				let id = this.res[index].id
				api.deleClass(token, id).then((res) => {
					console.log(res)
					if (res.code == 1) {
						this.res[index].isShow = false
					} else {
						if(res.errors == "未找到。")
						{
							uni.showModal({
								content:"无法退课"
							})
						}
					}

				}).catch((err) => {
					// console.log(err)
				})
			}
		}
	}
</script>

<style lang="less">
	.contain {
		.title {
			height: 100px;
			background-color: #a62618;
			line-height: 100px;
			text-align: center;
			font-size: 23px;
			color: white;
		}

		.list {
			background-color: white;
			height: calc(100vh - 200px);
			// margin-top: 12px;
			font-size: 12px;

			.items {
				margin-bottom: 10px;

				.time {
					height: 30px;
					line-height: 40px;
					background-color: #E5E5E5;
					display: flex;
					align-items: center;
					justify-content: space-between;

					.start {
						width: 350rpx;
					}

					.end {
						width: 350rpx;
						color: red;
					}
				}

				.info {
					font-weight: bold;
					height: 50px;
					// line-height: 80px;
					background-color: #F4F4F5;
					display: flex;
					align-items: center;
					justify-content: space-around;

					.coursename {
						width: 480rpx;
					}

					.teachername {
						width: 150rpx;
					}

					.number {
						width: 100rpx;
						color: #767A82;
					}

				}

				.info2 {
					font-weight: bold;
					height: 20px;
					// line-height: 80px;
					font-size: 10px;
					background-color: white;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin: 0 20rpx;

					.category {
						width: 200rpx;
					}

					.credit {
						width: 100rpx;
					}

					.hour {
						hour: 100rpx;
					}
				}
			}
		}
	}
</style>
